<?php


namespace App\Models\StoreCenter\Models;


use App\Models\ProductCenter\Models\SkuModel;
use App\Models\ProductCenter\Models\SpuModel;
use App\Models\StoreCenter\StoreCenterModel;

class OrderSkuInfoModel extends StoreCenterModel
{
    public $timestamps = false;
    public $table = 'order_sku_info';
    public $fillable = [
        'order_code', //varchar(32) NOT NULL DEFAULT '' COMMENT '订单号',
        'spu', //varchar(64) NOT NULL DEFAULT '' COMMENT 'spu',
        'sku', //varchar(64) NOT NULL DEFAULT '' COMMENT 'sku',
        'attribute', //json DEFAULT NULL COMMENT '属性',
        'sku_info', //json DEFAULT NULL COMMENT 'sku详情',
        'amount', //int NOT NULL DEFAULT '0' COMMENT '申请数量',
        'price',
        'actual_price', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '实际成交价格',
        'discount', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '折扣',
        'summary', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '小计',
        'shipping_fee', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '运费',
        'payment', //varchar(64) NOT NULL DEFAULT '' COMMENT '支付方式',
        'shipping_method', //varchar(64) CHARACTER NULL DEFAULT '' COMMENT '运送方式',
    ];
    public $casts = [
      'sku_info' => 'array'
    ];

    public function order()
    {
        return $this->belongsTo(OrderModel::class, 'order_code', 'order_code');
    }

    public function skuInfo()
    {
        return $this->belongsTo(SkuModel::class, 'sku', 'sku')->withDefault();
    }

    public function spuInfo()
    {
        return $this->belongsTo(SpuModel::class, 'spu', 'spu')->withDefault();
    }
}
